<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <div th:replace="common/common :: copy"></div>
    <title>添加班级 - 班级管理 - H-ui.admin v3.1</title>
    <meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
    <meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>班号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="classNO" name="classNO">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">
                <span class="c-red">*</span>院系：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
				<select  name="facultyNO" class="select valid" aria-required="true" aria-invalid="false">
					<option th:each="f : ${facultyList}" th:value="${f.facultyNO}" th:text="${f.facultyName}">全部类型</option>
				</select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>班级人数：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="classSize" name="classSize">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>入学年份：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" name="year" class="input-text datetimepicker-input" value="" readonly="" autocomplete="off" id="datetimepicker-demo-7">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">
                <span class="c-red">*</span>辅导员名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
				<select  name="counsellorNO" class="select valid" aria-required="true" aria-invalid="false">
					<option th:each="t : ${teacherList}" th:value="${t.teacherID}" th:text="${t.name}">全部类型</option>
				</select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input id="submit" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/jquery.validate.js}"></script>
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/validate-methods.js}"></script>
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/messages_zh.js}"></script>
<script type="text/javascript" th:inline="javascript">
    $(function () {
        $("#datetimepicker-demo-7").datetimepicker({
            language: "zh-cn",
            format: "yyyy-mm-dd",
            minView: 'month',
            autoclose: true,
            todayBtn: true
        });
            var ctxPath = [[@{/}]];
            $.validator.addMethod(  //添加自定义验证函数
                "validateClassNO",       //自定义验证函数的名称
                function(value,element,params){
                    var deferred = $.Deferred();//创建一个延迟对象
                    $.ajax({        //发送Ajax请求
                        type:"GET",
                        async:false,
                        url:ctxPath+"class/isAvailableClassNO",
                        dataType:"json",    //数据类型为json,发回的数据已自动解析
                        data:{
                            classNO:function(){return $("#classNO").val();},
                        },
                        success:function(data){
                            if (data.code==100) {
                                console.log(100)
                                deferred.resolve();
                            } else {
                                deferred.reject();
                            }
                        }
                    });
                    return deferred.state() == "resolved" ? true : false;
                },
                "班号重复，请重新输入！！！"
            );
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });
            $("#form-admin-add").validate({
                rules: {
                    classNO: {
                        required: true,
                        minlength: 1,
                        maxlength: 16,
                        validateClassNO:true
                    },
                    facultyNO: {
                        required: true,
                    },classSize: {
                        required: true,
                    },year: {
                        required: true,
                    },counsellorNO: {
                        required: true,
                    }
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'post',
                        url: ctxPath + "class/classAdd",
                        success: function (data) {
                            console.log(data)
                            if (data.code == 100) {
                                layer.msg('添加成功!', {icon: 1, time: 1000});
                                setTimeout(function() {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    window.parent.location.reload();
                                    parent.layer.close(index);
                                },2000)
                            }
                            if (data.code == 500) {
                                layer.msg('添加失败!', {icon: 2, time: 1000});
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg('error!', {icon: 1, time: 1000});
                        }
                    });

                }
            });
        })
</script>
</body>
</html>